<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>

<%@taglib uri="/struts-tags" prefix="s" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<style type="text/css">
img{
max-width:359px;
width:expression(this.width>360?"360px":this.width);
max-height:244px;
height:expression(this.height>245?"245px":this.height);
}
#id1{
	color:#F00;
}
</style>
<script type="text/javascript" src="${pageContext.request.contextPath}/jq/jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/upload/upload.js"></script>
<script type="text/javascript">
$(function(){
	new uploadPreview({UpBtn:"image",DivShow:"mypic",ImgShow:"pic"});
	
 	$("[type='submit']").click(function(){
		//判断旧密码是否正确
		var str="${pageContext.request.contextPath}/student/checkpwd";
		var flag=true;		
		$.ajax({
			type:"POST",
			async:false,//同步
			url:str,
			data:{"student.id":"${STUDENT.id}","student.pwd":$("#oldpwd").val()},
			success: function(data){
				if(data=="0"){
					$("#id1").html("旧密码输入不正确");
					$("#oldpwd").select()
					$("#oldpwd").focus();
					flag=false;
				}
			}
 		});
		if(!flag){			
			return flag;	
		}
		if($("[name='student.pwd']").val()!=$("#repwd").val()){//判断两次输入的新密码是否一致
			$("#id1").html("两次输入的密码不一致，请重新输入");			
			$("#repwd").select()
			$("#repwd").focus();
			return false;
		}
		return true;
	}); 
});
</script>
</head>
<body>
修改个人信息
<br/>
<br/>
<s:if test="#session.STUDENT.name==null">
	未登录
</s:if>
<table><tr><td width="341">
<form method="post" enctype="multipart/form-data" action="${pageContext.request.contextPath }/student/update">
<table>
<tr><td>用户名:</td><td><input type="text" name="student.name" value="${STUDENT.name }"/>
<input type="hidden" name="student.id" value="${STUDENT.id }"/></td></tr>
<tr><td>旧密码:</td><td><input type="password" id="oldpwd"/></td></tr>
<tr><td>新密码:</td><td><input type="password" name="student.pwd" value="${STUDENT.pwd }"/></td></tr>
<tr>
  <td>重复新密码:</td>
  <td><input type="password" id="repwd"/></td>
</tr>
<tr>
  <td>性别</td>
  <td><s:radio list="#{'男':'男','女':'女'}" name="student.sex" value="#session.STUDENT.sex"/></td>
</tr>
<tr>
  <td>年级:</td>
  <td><s:select name="student.grade" list="#{'一年级':'一年级','二年级':'二年级','三年级':'三年级','四年级':'四年级'}" value="#session.STUDENT.grade"></s:select></td>
</tr>
<tr><td>电话号码:</td><td><input type="text" name="student.phone" value="${STUDENT.phone }"/></td></tr>
<tr><td>上传照片:</td><td><input type="file" name="image" id="image"/>
<input type="hidden" name="student.photo" value="${STUDENT.photo }">
</td></tr>
<tr><td colspan="2"><input type="submit" value="提交"/></td></tr>
</table>
</form>
</td><td width="219">
<div id="mypic">
<s:if test="#session.STUDENT.photo==null">
	<img src="${pageContext.request.contextPath}/images/2.jpg" id="pic"/>
</s:if>
<s:else>
	<img src="${STUDENT.photo}" id="pic"/>	
</s:else>
</div>
</td></tr></table>
<div id="id1"></div>
<br/>
<br/>
<a href="${pageContext.request.contextPath}/main.jsp">返回主页</a>
</body>
</html>